$(function() {
    var favg_1 = false;
    var favg_2 = false;
    $(".button").click(function () {
        if (favg_1 && favg_2){
            var EMail = $("#EMail").val();
            var password = $("#password").val();
            $.ajax({
                url: "account_update_password?email=" + EMail + "&password=" + password,
                type: "get",
                dataType: "json",
                success: function (res) {
                    if (res) {
                        alert("密码修改成功！自动跳转到登录页面！！");
                        window.location.href = "/MyXiaomiShop/login.jsp"
                    } else {
                        alert("重置密码错误，请查看你输入的邮箱");
                    }
                },
                error: function (res) {
                    alert("获取失败，请联系程序员解决!");
                }
            });
        }else {
            alert("请根据输入框，下方提示来重置密码");
        }
    });

    $("#EMail").change(function () {
        var EMail = $("#EMail").val();
        var email =  /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
        if (EMail.trim().length==0){
            document.getElementById("EMail_text").innerText = "请输入邮箱";
        }else if ( email.test(EMail)){
            favg_1 = true;
            document.getElementById("EMail_text").innerText = " ";
        }else {
            document.getElementById("EMail_text").innerText = "邮箱错误！！";
        }
    });

    $("#password").change(function () {
        var password = $("#password").val();
        var pass = /^[\w]{6,12}$/;
        if (password.trim().length == 0) {
            document.getElementById("password_text").innerText = "请输入密码(6-12的英文和数字、字符)";
        }else if (pass.test(password)){
            favg_2 = true;
            document.getElementById("password_text").innerText = " ";
        }else{
            document.getElementById("password_text").innerText = "密码格式错误！！";
        }
    })
});